/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.nju.software.greencreditsystem.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.Map;

/**
 * 作者：韩天
 * 创建时间：2011-8-15
 * 类描述：检查企业用户是否登录的拦截器
 */
public class EnterpriseLoginInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        
        //取得请求相关的ActionContext实例  
        ActionContext context = invocation.getInvocationContext();  
        Map session = context.getSession();
        String userName = (String)session.get("userName");
  
        // 如果没有登陆，返回重新登陆  
        if (userName == null) {
            return "unlogin";
        }else if(Integer.valueOf((String)session.get("userId")) < 0){
            return "noright";
        }else{
            return invocation.invoke(); 
        }
   
    }
    
}
